package com.heima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.VmTypeMapper;
import com.heima.pojo.VmType;
import com.heima.pojo.dto.AddVmTypeDTO;
import com.heima.pojo.dto.PageSearchDTO;
import com.heima.pojo.vo.PageSearchQueryVO;
import com.heima.pojo.vo.VmTypeVO;
import com.heima.service.VmTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VmTypeServiceImpl implements VmTypeService {

    @Autowired
    VmTypeMapper vmTypeMapper;

    /**
     * 设备分页搜索
     */
    @Override
    public PageSearchQueryVO search(PageSearchDTO dto) {
        //开启分页
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        //查询数据库中的数据
        Page<VmType> page =vmTypeMapper.search(dto);
        PageSearchQueryVO vo = new PageSearchQueryVO();
        vo.setPageSize(dto.getPageSize());
        vo.setPageIndex(dto.getPageIndex());
        vo.setTotalPage(page.getPages());
        vo.setTotalCount((int) page.getTotal());
        vo.setCurrentPageRecords(page.getResult());
        return vo;
    }
    /**
     * 新增设备类型
     * */
    @Override
    public void add(AddVmTypeDTO dto) {
      vmTypeMapper.add(dto);
    }
}
